// pages/train/train-list/trainList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasStudyPower:false,
    hasTrainPower:false,
    hasExamPower:false,
    trainingLibraryId: '',
    list: [],
    noData: false,
    CDNPATH: app.globalData.CDNPATH,
    packageInfo: {},
    opening: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { trainingLibraryId, packageId} = options
    wx.setNavigationBarTitle({
      title: '训练详情'
    })
    this.setData({
      trainingLibraryId,
      packageId
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const permissionCodes = app.globalData.permissionCodes || []
    console.log(permissionCodes,'permissionCodes!!!!');
    this.setData({
      hasStudyPower:permissionCodes.includes('train_study'),
      hasTrainPower:permissionCodes.includes('rehearse'),
      hasExamPower:permissionCodes.includes('customs_clearance'),
    })
    this.getSceneList()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getProductList () {
    const { trainingLibraryId } = this.data
    app.api.post({
      url: 'training_vx_product_list',
      data: {
        trainingLibraryId
      }
    }).then(res => {
      this.setData({ list: res, noData: res.length <= 0 })
    })
  },
  getSceneList () {
    const { packageId } = this.data
    app.api.get({
      url: 'qryUserTrainScene',
      data: {
        packageId
      }
    }).then(res => {
      this.setData({ list: res, noData: res.length <= 0 })
    })
    // 场景包详情
    app.api.get({
      url: 'qryTrainScenePackageDetail',
      data: {
        id:packageId
      }
    }).then(res => {
      this.setData({ packageInfo: res })
    })
  },
  openOrClose () {
    this.setData({ opening: !this.data.opening })
  }
})